package com.heima.controller;


import com.heima.model.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UserDeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String userId;
        UserDao dao = new UserDao();
        int result=0;
        PrintWriter out = null;
        //1.调用请对象，获取请求头中的参数（用户id）
        userId = request.getParameter("userId");
        //2.调用DAO，将用户编号填充到delete命令并发送到数据库服务器，实现删除操作
        result = dao.delete(userId);
        //3.调用响应对象，将处理结果以二进制的形式写入到响应体中，交给浏览器
        response.setContentType("text/html;charset=utf-8");
        out=response.getWriter();
        if(result==0){
            out.print("<font style='color:green;font-size:40'><center>用户信息删除失败</center></font>");
        }else{
            out.print("<font style='color:green;font-size:40'><center>用户信息删除成功<center></font>");
        }
    }
}
